package com.tanjun.web.service;

import com.tanjun.common.model.LoginUserInfo;

import java.util.List;

public class LoginUserContext {
    private static final ThreadLocal<LoginUserInfo> threadLocalUserInfo = new ThreadLocal<>();
    private static final ThreadLocal<List<String>> threadLocalUserRoles = new ThreadLocal<>();
    private static final ThreadLocal<List<String>> threadLocalUserPermission = new ThreadLocal<>();

    public static LoginUserInfo getLoginUserInfo() {
        return threadLocalUserInfo.get();
    }
    public static void setLoginUserInfo(LoginUserInfo loginUserInfo) {
        threadLocalUserInfo.set(loginUserInfo);
    }
    /**
     * 防止线程复用，导致第二次请求获取到上次信息
     */
    public static void clearUserInfo() {
        threadLocalUserInfo.remove();
    }
    /*********************用户角色**********************************/
    public static List<String> getUserRoles() {
        return threadLocalUserRoles.get();
    }
    public static void setUserRoles(List<String> userRoles) {
        threadLocalUserRoles.set(userRoles);
    }
    public static void clearUserRoles() {
        threadLocalUserRoles.remove();
    }


    /***************************************************************/
    /**
     * 用户权限版本
     * @return
     */
    public static List<String> getPermission() {
        return threadLocalUserPermission.get();
    }

    public static void setPermissionVersion(List<String> permissions) {
        threadLocalUserPermission.set(permissions);
    }

    public static void clearPermission() {
        threadLocalUserPermission.remove();
    }

}
